Java Programming Strings and Wrappers

This programming assignment is designed to evaluate your knowledge, comprehension and application of Java String and primitive data type Wrapper classes. It is expected that a program can be written that compiles and runs correctly. You should work on this programming assignment on your own. However, collaboration with others on general logic flow, techniques and Java Core API methods available may be useful. It is most beneficial if you do not share code.

Program: Write a Java program that accepts text input from the keyboard, performs the operations specified below. Accept more text input until just the "enter" key is inputted, at that point exit the program. For this program you will need to use the java.lang.String and java.lang.Integer objects and methods associated with each.

  1. Separate the keyboard input into a string that contains the input from the beginning up to but NOT including the comma and the integer value after the comma into an int variable.
  2. Display the text string and its length, and the int value.
  3. Test if the text string starts with the word, "This" and display true or false.
  4. Test if the text string ends with the word, "test" and display true or false.
  5. Display the text string in all upper case.
  6. Display the text string in all lower case.
  7. If the text string is more than 10 characters long, display the 9th character.
  8. Compare the 9th character with capital ‘A’ and display if it is equal or not.
  9. Concatenate the text string with the string ". This is the next sentence."
  10. Using the original keyboard input replace the comma (,) with a period (.) and display.
  11. Display the 3rd through 12th characters of the text string if it is longer than 12 characters.

12. Display the binary, octal and hex string of the int variable.

 

Sample screen output during a particular running of the program:

Enter a string of text followed by a comma (,) and an integer value: This is a test, -32

Text: This is a test

Length: 14

Int: -32

Starts with "This"? true

Ends with "test"? true

THIS IS A TEST

this is a test

a

a not equal to A

This is a test. This is the next sentence.

This is a test. –32

is is a te

11111111111111111111111111100000

37777777740

FFFFFFE0

 

The name of the object must be Ex5. To run the program, the Ex5 Java object is invoked. The Ex5 skeleton source code is presented below and should be used. This source code should be put in a file named Ex5.java and then compiled. When it is compiled the object that is run will be called Ex5.class. The entire program can be implemented in the main method.

IMPORTANT: The file for this program must be named Ex5.java. (Not EX05, ex5, or any other variation). Your file must be should placed in a subdirectory for this project. I suggest something like C:\javacode\Ex5\

 

Ex5.java code:

import java.io.*;
           
public class Ex5
{
              
  Ex5()
  {
  }
             
  public static void main(String args[])
  {
   BufferedReader console;
   console = new BufferedReader(new InputStreamReader(System.in));
      
   String intstring = "";


   do
   {
    try
    {
     System.out.print("prompt");
     intstring = console.readLine();
    }
    catch (IOException e)
    {
     //ignore exception
    }
         
    if (intstring.equals(""))
    {
     break;
    }
         
//insert logic here        

   } while (true);
     
  } //end main
   
} //end of Ex5 class